package com.queclink.ycm.entity.data.useless;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.queclink.ycm.common.utils.HexUtils;
import com.queclink.ycm.entity.data.Data;

/**
 * @author jim.li
 * @email jim.li@queclink.com
 * @date 2021-12-27 11:26:00
 */
public class Data140 extends Data {

    @JSONField(
            name = "Type"
    )
    private String Type;
    @JSONField(
            name = "MaximumAcceleration"
    )
    private String MaximumAcceleration;

    public String getType(JSONObject jsonObject) {
        StringBuffer sb = new StringBuffer();
        String type = jsonObject.getString("Type");
        sb.append(type);
        while (sb.length() < 2) {
            sb.insert(0, "0");
        }
        return sb.toString();
    }

    public void setType(String type) {
        Type = type;
    }

    public String getMaximumAcceleration(JSONObject jsonObject) {
        StringBuffer sb = new StringBuffer();
        Integer maximumAcceleration = jsonObject.getInteger("MaximumAcceleration");
        String s = HexUtils.intToHex(maximumAcceleration, 4);
        sb.append(s);
        return sb.toString();
    }

    public void setMaximumAcceleration(String maximumAcceleration) {
        MaximumAcceleration = maximumAcceleration;
    }

    public String getDataID() {
        // data140
        return "808c";
    }

    public String getLength() {
        return "09";
    }

    @Override
    public String combine(JSONObject jsonObject) throws Exception {
        StringBuffer sb = new StringBuffer();
        sb.append(this.getDataID());
        sb.append(this.getLength());
        sb.append(this.getType(jsonObject));
        sb.append(this.getMaximumAcceleration(jsonObject));
        sb.append("000000000000");
        return sb.toString();
    }
}
